home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / network.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  9.4 KB  |  362 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/DTR/RCS/network.c,v 1.12 92/05/29 12:42:16 drapeau Exp $*/
  25. /* $log$ */
  26. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/network.c,v 1.12 92/05/29 12:42:16 drapeau Exp $";
  27.  
  28. #include "dtr.h"
  29. #include "dtr_ui.h"
  30. #include <getopt.h>
  31.  
  32. extern  dtr_editListPanelPopUp_objects*    dtr_editListPanelPopUp;
  33. extern dtr_mainWindow_objects*        dtr_mainWindow;
  34.  
  35. char  oldFileName[MAXPATHLEN];
  36.  
  37.  
  38. void CheckOptions(argc, argv)
  39.      int     argc;
  40.      char     **argv;
  41. {
  42.   int optionChar;  
  43.   int option_index = 0;
  44.   static struct option long_options[] =
  45.   {
  46.     {"hostname", 1, 0, 'h'},        
  47.     {"portnumber", 1, 0, 'p'},
  48.     {0, 0, 0, 0}
  49.   };
  50.  
  51.   while (1)                                /* Start parsing all known options */
  52.   {
  53.     optionChar = getopt_long_only (argc, argv, "h:p:",
  54.                    long_options, &option_index);
  55.     if (optionChar == EOF)                        /* Done with all known options */
  56.     {
  57.       break;
  58.     }
  59.     switch (optionChar)
  60.     {
  61.      case 'h':
  62.       if (optarg) 
  63.       {
  64.     senderPort.hostName = (char *)malloc(sizeof(optarg) + 2);
  65.     strcpy (senderPort.hostName, optarg);
  66.       }
  67.       break;
  68.      case 'p':
  69.       if (optarg) 
  70.       {
  71.     ReceiverPortNumber = atoi(optarg);
  72.       }
  73.       break;
  74.      default:
  75.       break;
  76.     }
  77.   }
  78.   if (optind < argc)                            /* Check if a filename has been specified */
  79.   {
  80.     Browse(argv[optind], BrowseCheckOpen,
  81.        IS_EDITLIST, documentFirstLine, documentFileType);
  82.     xv_set(dtr_editListPanelPopUp->editListPanelPopUp,
  83.        FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  84.     xv_set(dtr_editListPanelPopUp->editListPanelPopUp,
  85.        XV_SHOW, TRUE, NULL);
  86.   }
  87. }
  88.  
  89.  
  90. void
  91.   InitNetwork(argc, argv)
  92. int  argc;
  93. char **argv;
  94. {
  95.   static DispatchTable            DT = 
  96.   {
  97.     OpenDoc,
  98.     GetDoc,
  99.     GetSelection,
  100.     SetSelection,
  101.     PerformSelection,
  102.     NULL,
  103.     NULL,
  104.     NULL,
  105.     NULL,
  106.     NULL,
  107.     NULL,
  108.     HaltSelection,
  109.     PauseSelection,
  110.     ResumeSelection,
  111.     HideApplication,
  112.     ShowApplication,
  113.     GetAppIcon
  114.     };
  115.   
  116.   senderPort.hostName = "localhost";
  117.   senderPort.portNumber = AnyPort;
  118.   sprintf(currentSoundFile,"Untitled");
  119.   CheckOptions(argc, argv);
  120.   senderPort.portNumber = PortMgrPortNumber;
  121.   sender = NewSender(&senderPort);
  122.   if (sender == NULL)
  123.   {
  124.     AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  125.             "Error:  PortManager seems to be absent.  Please start PortManager again.");
  126.     exit(0);
  127.   }
  128.   receiver = NewReceiver(sender, "DTR", ReceiverPortNumber);
  129.   BuildDispatchTable(&DT);
  130.   strcpy(oldFileName, "Untitled");
  131.   SoundBufferReady = FALSE;
  132.   (void) notify_enable_rpc_svc(TRUE);
  133. }                                    /* end function InitNetwork */
  134.  
  135.  
  136.  
  137. void
  138.   OpenDoc(editListName)
  139. char  **editListName;
  140. {
  141.   static  char     *lastEditListOpened = "Untitled";
  142.   struct  stat     fileInfo;
  143.   int              result;
  144.  
  145.   StopPlay();
  146. /*
  147.   SetWaveEditModeOff();
  148. */
  149.   SoundBufferReady = FALSE;
  150.   if (*editListName == NULL)                        /*  If an invalid editlist name is being requested, */
  151.   {
  152.     AlertByNoticePrompt(dtr_editListPanelPopUp->editListPanelPopUp,
  153.             "Error:  The name of the edit-list is NULL");
  154.     return;                                /*  ...return w/o doing anything.                   */
  155.   }
  156.   if (strcmp(*editListName, lastEditListOpened) == 0)
  157.   {                                    /*  If the last editlist opened is the same as...   */
  158.     return;                                /*  ...the current one, return w/o doing anything.  */
  159.   }
  160.   lastEditListOpened = (char *)strdup(*editListName);            /*  Duplicate the filename.                         */
  161.   result = stat(*editListName, &fileInfo);                /*  Check if the editlist file exists.              */
  162.   if ((result == 0) && (!(fileInfo.st_mode & S_IFDIR)))
  163.     ReadEditListFromFile(*editListName, NON_USER);
  164.   else
  165.   {
  166.     AlertByNoticePrompt(dtr_editListPanelPopUp->editListPanelPopUp,
  167.             "Error:  Edit-list not found/not valid.");
  168.   }
  169.  
  170. /****************
  171.   if (strcmp(fullFilename, oldFileName) == 0)
  172.   {
  173.     FileReady = TRUE;
  174.     SameSoundFile = TRUE;
  175.   }
  176.   else
  177.   {
  178.     FileReady = FALSE;
  179.     SameSoundFile = FALSE;
  180.   }
  181.   strcpy(oldFileName, fullFilename);
  182.   sprintf(currentSoundFile,"%s",fullFilename);
  183.   UpdateHeader(FALSE);
  184.  
  185.   SoundBufferReady = ReadSoundFile(TRUE);
  186.   SameSoundFile = TRUE;
  187.             
  188.   WaveCanvasRightMarkerSet = FALSE;
  189.   GlobalWaveCanvasRightMarkerSet = FALSE;
  190. **************/
  191. }                                    /* end function OpenDoc */
  192.  
  193.  
  194. void SetSelection(MAESelection* selection)
  195. {
  196.   int                        entry;
  197.   int                           gain;
  198.   double                    startingTimeInSec;
  199.   double                    endingTimeInSec;
  200.   
  201.   if (selection->start >= EditList.numItems)
  202.   {
  203.     AlertByNoticePrompt(dtr_editListPanelPopUp->editListPanelPopUp,
  204.             "Error:  Illegal edit number.");
  205.     return;
  206.   }
  207.   entry = selection->start;
  208.   if (currentSelection != NO_CURRENT_EDIT)
  209.   {
  210.     xv_set (dtr_editListPanelPopUp->editListScrollList,
  211.         PANEL_LIST_SELECT, currentSelection, FALSE,
  212.         NULL);
  213.   }
  214.   currentSelection = entry;                        /*  Select the item in the Scroll list.             */
  215.   xv_set(dtr_editListPanelPopUp->editListScrollList,            
  216.      PANEL_LIST_SELECT, entry, TRUE,
  217.      NULL);
  218.   SetCurrentSelection(entry, selection);
  219.   return;
  220. }                                    /* end function SetSelection */
  221.  
  222.  
  223.  
  224. void PerformSelection(MAESelection* selection)
  225. {
  226.   StopPlay();
  227.   DisableEditListPanel();
  228.   Play(dtr_mainWindow);
  229.   EnableEditListPanel();
  230. }
  231.  
  232.  
  233. char **
  234.   GetDoc(unusedArg)
  235. void *unusedArg;
  236. {
  237.   static  char   *returnValue;
  238.  
  239.   if (NullFileName(absoluteEditListName) ||
  240.       strcmp(absoluteEditListName, "Untitled") == 0 ||
  241.       strcmp(absoluteEditListName, "NoneSpecified") == 0)
  242.   {
  243.     AlertByNoticePrompt(dtr_editListPanelPopUp->editListPanelPopUp,
  244.             "Warning:  The edit list is untitled.");
  245.     returnValue = (char *)strdup("Untitled");
  246.   }
  247.   else
  248.   {
  249.     returnValue = absoluteEditListName;
  250.   }
  251.   return(&returnValue);
  252. }                                    /* end function GetDoc */
  253.  
  254.  
  255.  
  256. MAESelection* GetSelection(void* unusedArg)
  257. {
  258.   static MAESelection select;
  259.   
  260.   if (currentSelection == NO_CURRENT_EDIT)                /*  Return select.duration = -1 if there is no...   */
  261.   {                                    /*  ...current MAESelection.                        */
  262.     select.duration = -1;
  263.     return(&select);
  264.   }
  265.   select.start = currentSelection;
  266.   select.end = currentSelection;
  267.   select.offset = 0;
  268.   select.duration = irint(((EditList.endingMin[currentSelection] - EditList.startingMin[currentSelection]) * 60.0
  269.                + EditList.endingSec[currentSelection] - EditList.startingSec[currentSelection]) * 1000);
  270.   if (strlen(EditList.label[currentSelection]) == 0)            /*  Return the label of the edit to be the label...  */
  271.   {                                    /*  ...of the note on TimeLine.                      */
  272.     strcpy(select.label, "No Label");
  273.   }
  274.   else
  275.   {
  276.     strcpy(select.label, EditList.label[currentSelection]);
  277.   }
  278.   return(&select);
  279. }                                    /* end function GetSelection */
  280.  
  281.  
  282. void
  283.   HaltSelection(MAESelection* selection)
  284. {
  285.   StopPlay();
  286.   XFlush((Display *) xv_get(dtr_mainWindow->mainWindow,
  287.                 XV_DISPLAY));
  288. }
  289.  
  290.  
  291. void
  292.   PauseSelection()
  293. {
  294.   Pause();
  295. }
  296.  
  297.  
  298. void
  299.   ResumeSelection()
  300. {
  301.   Pause();
  302. }
  303.  
  304.  
  305. void
  306.   HideApplication()
  307. {
  308.   xv_set(dtr_mainWindow->mainWindow, FRAME_CLOSED, TRUE, NULL);
  309.   XFlush((Display *) xv_get(dtr_mainWindow->mainWindow, 
  310.                 XV_DISPLAY));
  311. }
  312.  
  313.  
  314. void
  315.   ShowApplication()
  316. {
  317.   extern   dtr_globalWaveCanvasPopUp_objects     *dtr_globalWaveCanvasPopUp;
  318.   extern   dtr_infoPopUp_objects                 *dtr_infoPopUp;
  319.   
  320.   xv_set(dtr_mainWindow->mainWindow, FRAME_CLOSED, FALSE, NULL);
  321.   if (xv_get(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, XV_SHOW) == (BOOL) TRUE)
  322.   {
  323.     xv_set(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, XV_SHOW, TRUE, NULL);
  324.   }
  325.   if (xv_get(dtr_editListPanelPopUp->editListPanelPopUp, XV_SHOW) == (BOOL) TRUE)
  326.   {
  327.     xv_set(dtr_editListPanelPopUp->editListPanelPopUp, XV_SHOW, TRUE, NULL);
  328.   }
  329.   if (xv_get(dtr_infoPopUp->infoPopUp, XV_SHOW) == (BOOL) TRUE)
  330.   {
  331.     xv_set(dtr_infoPopUp->infoPopUp, XV_SHOW, TRUE, NULL);
  332.   }
  333.   XRaiseWindow((Display *)xv_get(dtr_mainWindow->mainWindow, XV_DISPLAY),
  334.            (Window) xv_get(dtr_mainWindow->mainWindow, XV_XID));
  335.   XFlush((Display *) xv_get(dtr_mainWindow->mainWindow, 
  336.                 XV_DISPLAY));
  337. }                                    /* end function ShowApplication */
  338.  
  339.  
  340. IconData *
  341.   GetAppIcon()
  342. {
  343.   static IconData returnVal;
  344.   static unsigned short mainWindow_bits[] = {
  345. #include "icons/dtr.icon"
  346.         };
  347.  
  348.   returnVal.iconData = (char *)malloc(sizeof(mainWindow_bits));
  349.   bcopy(mainWindow_bits, returnVal.iconData, sizeof(mainWindow_bits));
  350.  
  351.   if (returnVal.iconData)
  352.     returnVal.dataLength = sizeof(mainWindow_bits);
  353.  
  354.   return(&returnVal);
  355. }
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.